package com.bbzn.device.client.controller;

import com.bbzn.device.client.dataobject.AppVersion;
import com.bbzn.device.client.service.AppVersionService;
import com.bbzn.device.client.utils.BaseApiService;
import com.bbzn.device.client.utils.BaseResponse;
import com.bbzn.device.client.utils.OptionalBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author wulongbo
 * @Date 2021/12/22 16:05
 * @Version 1.0
 */

@RestController
@RequestMapping("/androidUpload")
@Api(tags = "Android上传设备数据")
public class AndroidController extends BaseApiService {

    @Autowired
    private AppVersionService appVersionService;

    /**
     * Android设备核对当前版本号
     *
     * @return
     */
    @ApiOperation(value = "Android设备核对当前版本号", notes = "Android设备核对当前版本号")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "watchType", dataType = "int", required = true, value = "【0：app / 1：司法 / 2：宠物定位器 / 3：智能头盔 / 4：儿童手表 / 5：成人手表】")})
    @PostMapping(value = "/deviceCheckVersion")
    public BaseResponse deviceCheckVersion(Integer watchType) throws Exception {
        if (!OptionalBean.ofNullable(watchType).isPresent()) {
            return setResultError("类型值不能为空！");
        }
        AppVersion appVersion = new AppVersion();
        appVersion.setType(watchType);
        List<AppVersion> appVersions = appVersionService.selectSelective(appVersion);
        if (CollectionUtils.isNotEmpty(appVersions)) {
            appVersion = appVersions.get(0);
        }
        return setResult(0,"请求成功",appVersion);
    }
}
